package com.yankaizhang.blog.service.impl;

import com.yankaizhang.blog.entity.Article;
import com.yankaizhang.blog.mapper.ArticleMapper;
import com.yankaizhang.blog.service.ArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Yankai
 * @since 2020-10-02
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    @Override
    public HashMap<Integer, List<Article>> getArchiveMap() {
        List<Integer> years = articleMapper.getYears();
        HashMap<Integer, List<Article>> map = new HashMap<>();
        if (years.size()==0){
            return map;
        }
        for (Integer year : years) {
            map.put(year, getArticlesByYear(year));
        }
        return map;
    }

    @Override
    public Integer getArticleCount() {
        return articleMapper.getArticleCount();
    }

    @Override
    public Integer getTotalViews() {
        return articleMapper.getTotalViews();
    }

    @Override
    public List<Article> getArticleByTag(String decode) {
        return articleMapper.getArticleByTag(decode);
    }

    public List<Article> getArticlesByYear(Integer year){
        return articleMapper.getArticlesByYear(year);
    }

}
